/*
 * @Author: 胡海
 * @Date: 2020-02-21 18:23:26
 * @LastEditors: 胡海
 * @LastEditTime: 2020-03-07 21:17:44
 * @Description: 
 */
const {
    sequelize
} = require('../../core/db.js')


const {
    Sequelize,
    Model
} = require('sequelize')

// define
class UserInfo extends Model {
    // 业务表
    static async addInfo(data) {
        const info = await UserInfo.findOne({
            where: {
                uid: data.uid
            }
        })
        if (info) {
            throw new global.errs.LikeError('用户信息已存在')
        }
        return await UserInfo.create({
            auth: data.auth,
            uid: data.uid,
            menu: data.menu
        })
    }
}

UserInfo.init({
    menu: Sequelize.STRING,
    auth: Sequelize.INTEGER,
    uid: Sequelize.INTEGER,
    avatar: Sequelize.STRING,
}, {
    sequelize,
    tableName: 'userInfo'
})

module.exports = {
    UserInfo
}

// 数据迁移 SQL 更新 风险